﻿<!--#include file="conn.asp"#-->
<!--#include file="sessao.asp"#-->
<!--#include file="getsessao.asp"#-->
<!--#include file="fn_multiselect.asp"#-->
<!--#include file="fn_combo.asp"#-->
<%

Select Case request("acao")
	Case "getAssunto"
		getAssunto()
	Case "getStatus"
		getStatus()
	Case "getRegional"
		getRegional()
	Case "getUF"
		getUF()
	Case "getDDD"
		getDDD()
	Case "getRegionalUF"
		getRegionalUF()
	Case "getRegionalUFDDD"
		getRegionalUFDDD()
	Case "getArea"
		getArea()
	Case "getCargo"
		getCargo()
	Case "getCount"
		getCount()
	Case "getTemplates"
		getTemplates()
	Case "getLayout"
		getLayout()
	Case "gravar"
		gravar()
	Case "getComunicado"
		getComunicado()
	Case "duplicar"
		duplicar()
	Case "getCountFiltros"
		getCountFiltros()
end Select

Sub getAssunto()
	Dim db_string
	db_string = " select a.cod_assunto_informativo,a.desc_assunto,case when isnull(i.cod_assunto_informativo,0) <> 0 then 1 else 0 end as selected from informativos.tb_assunto_informativo as a "
	db_string = db_string & " left outer join informativos.tb_informativos as i "
	db_string = db_string & " on i.cod_informativo="&request("cod_informativo")&" and i.cod_assunto_informativo=a.cod_assunto_informativo "
	db_string = db_string & " order by a.desc_assunto "
	retorno  = fn_combo(db_string,true,"")
	response.write retorno
End Sub

Sub getStatus()
	Dim db_string
	db_string = " select a.cod_status_informativo,a.desc_status_informativo,case when isnull(i.cod_status_informativo,0) <> 0 then 1 else 0 end as selected from informativos.tb_status_informativo as a "
	db_string = db_string & " left outer join informativos.tb_informativos as i "
	db_string = db_string & " on i.cod_informativo="&request("cod_informativo")&" and i.cod_status_informativo=a.cod_status_informativo "
	db_string = db_string & " where a.cod_status_informativo in(1,3) "
	db_string = db_string & " order by a.desc_status_informativo "
	retorno  = fn_combo(db_string,true,"")
	response.write retorno
End Sub


sub getRegional()
	Dim db_string 
	db_string = "select reg.cod_regional,reg.sigla_regional,case when isnull(rp.cod_informativo,0) <> 0 then 'checked' else '' end as checked from informacao.tb_regionais as reg"
	db_string = db_string & " left outer join informativos.tb_informativos_regional as rp "
	db_string = db_string & " on rp.cod_informativo="&request("cod_informativo")&" and filtro="&request("cod_filtro")&" and rp.cod_regional=reg.cod_regional "
	db_string = db_string & " order by reg.sigla_regional "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
end Sub


Sub getUF()
	Dim db_string
	db_string = "select uf.cod_uf,uf.uf,case when isnull(uff.cod_informativo,0) <> 0 then 'checked' else '' end as checked from informacao.tb_ufs as uf "
	db_string = db_string & " left outer join informativos.tb_informativos_uf as uff "
	db_string = db_string & " on uff.cod_informativo="&request("cod_informativo")&" and filtro="&request("cod_filtro")&" and uf.cod_uf=uff.cod_uf "
	db_string = db_string & " order by uf.uf "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub


Sub getDDD()
	Dim db_string
	db_string = "select ddd.cod_ddd,ddd.ddd,case when isnull(dddu.cod_informativo,0) <> 0 then 'checked' else '' end as checked from informacao.tb_ddds as ddd "
	db_string = db_string & " left outer join informativos.tb_informativos_ddd as dddu "
	db_string = db_string & " on dddu.cod_informativo="&request("cod_informativo")&" and filtro="&request("cod_filtro")&" and dddu.cod_ddd=ddd.cod_ddd "
	db_string = db_string & " order by ddd.ddd "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getRegionalUF()
	Dim db_string
	db_string = "select distinct uf.cod_uf,uf.uf,case when isnull(uff.cod_informativo,0) <> 0 then 'checked' else '' end as checked from informacao.tb_ufs as uf "
	db_string = db_string & " inner join informacao.tb_regional_uf as ruf on ruf.cod_uf=uf.cod_uf and ruf.cod_regional in("&request("ids")&") "
	db_string = db_string & " left outer join informativos.tb_informativos_uf as uff "
	db_string = db_string & " on uff.cod_informativo="&request("cod_informativo")&" and uff.filtro="&request("cod_filtro")&" and uf.cod_uf=uff.cod_uf "
	db_string = db_string & " order by uf.uf "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getRegionalUFDDD()
	Dim db_string
	db_string = "select distinct ddd.cod_ddd,ddd.ddd,case when isnull(dddu.cod_informativo,0) <> 0 then 'checked' else '' end as checked from informacao.tb_ddds as ddd "
	db_string = db_string & " inner join informacao.tb_regional_uf_ddd as ruddd on ddd.cod_ddd=ruddd.cod_ddd "
	if request("idregs") <> "" then
		db_string = db_string & " and ruddd.cod_regional in("&request("idregs")&")"
	end if
	if request("idufs") <> "" then
		db_string = db_string & " and ruddd.cod_uf in("&request("idufs")&")"
	end if
	db_string = db_string & " left outer join informativos.tb_informativos_ddd as dddu "
	db_string = db_string & " on dddu.cod_informativo="&request("cod_informativo")&" and dddu.filtro="&request("cod_filtro")&" and dddu.cod_ddd=ddd.cod_ddd "
	db_string = db_string & " order by ddd.ddd "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub


Sub getArea()
	Dim db_string
	db_string = " select a.cod_area,a.desc_area,case when isnull(ua.cod_area,0) <> 0 then 'checked' else '' end as selected from informacao.tb_areas as a "
	db_string = db_string & " left outer join informativos.tb_informativos_area as ua "
	db_string = db_string & " on ua.cod_informativo="&request("cod_informativo")&" and ua.filtro="&request("cod_filtro")&" and ua.cod_area=a.cod_area "
	db_string = db_string & " where a.cod_status_area=1 "
	db_string = db_string & " order by a.desc_area "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getCargo()
	Dim db_string
	db_string = " select a.cod_cargo,a.desc_cargo,case when isnull(ua.cod_cargo,0) <> 0 then 'checked'  else '' end as checked from informacao.tb_cargos as a "
	db_string = db_string & " left outer join informativos.tb_informativos_cargo as ua "
	db_string = db_string & " on ua.cod_informativo="&request("cod_informativo")&" and ua.filtro="&request("cod_filtro")&" and ua.cod_cargo=a.cod_cargo "
	db_string = db_string & " where a.cod_status_cargo=1 "
	db_string = db_string & " order by a.desc_cargo "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getCount()
	Dim db_string
	Dim db_total
	Dim arr
	Dim rscount
	Dim retorno
	Dim i

	if request("filtros") <> "" then
		arr = split(request("filtros"),",")
		retorno = ""
		db_total = ""
		for i=0 to ubound(arr)
			if request("chk_reg_filtro"&arr(i)&"_select") <> "" or request("chk_uf_filtro"&arr(i)&"_select") <> "" or request("chk_ddd_filtro"&arr(i)&"_select") <> "" or request("chk_area_filtro"&arr(i)&"_select") <> "" or request("chk_cargo_filtro"&arr(i)&"_select") <> "" then

				db_string = "select COUNT(a.cod_usuario) as qtde "

				db_string = db_string & " from ("
				db_string = db_string & " select distinct u.cod_usuario from informativo.informacao.tb_usuarios as u "

				if i > 0 then
					if db_total <> "" then
						db_total = db_total & " union "
					end if
				end if

				db_total = db_total & "select distinct u.cod_usuario from informativo.informacao.tb_usuarios as u "

				if request("chk_reg_filtro"&arr(i)&"_select") <> "" then
					db_string = db_string & " inner join informativo.informacao.tb_usuario_regional as ur "
					db_string = db_string & "	on ur.cod_usuario=u.cod_usuario "
					db_string = db_string & " 	and ur.cod_regional in("&request("chk_reg_filtro"&arr(i)&"_select")&") "

					db_total = db_total & " inner join informativo.informacao.tb_usuario_regional as ur "
					db_total = db_total & "	on ur.cod_usuario=u.cod_usuario "
					db_total = db_total & " 	and ur.cod_regional in("&request("chk_reg_filtro"&arr(i)&"_select")&") "
				end if
				if request("chk_uf_filtro"&arr(i)&"_select") <> "" then
					db_string = db_string & " inner join informativo.informacao.tb_usuario_uf as uf "
					db_string = db_string & "	on uf.cod_usuario=u.cod_usuario "
					db_string = db_string & " 	and uf.cod_uf in("&request("chk_uf_filtro"&arr(i)&"_select")&")"

					db_total = db_total & " inner join informativo.informacao.tb_usuario_uf as uf "
					db_total = db_total & "	on uf.cod_usuario=u.cod_usuario "
					db_total = db_total & " 	and uf.cod_uf in("&request("chk_uf_filtro"&arr(i)&"_select")&") "
				end if
				if request("chk_ddd_filtro"&arr(i)&"_select") <> "" then
					db_string = db_string & " inner join informativo.informacao.tb_usuario_ddd as ddd "
					db_string = db_string & "	on ddd.cod_usuario=u.cod_usuario "
					db_string = db_string & " 	and ddd.cod_ddd in("&request("chk_ddd_filtro"&arr(i)&"_select")&") " 

					db_total = db_total & " inner join informativo.informacao.tb_usuario_ddd as ddd "
					db_total = db_total & "	on ddd.cod_usuario=u.cod_usuario "
					db_total = db_total & " 	and ddd.cod_ddd in("&request("chk_ddd_filtro"&arr(i)&"_select")&") "
				end if
				if request("chk_area_filtro"&arr(i)&"_select") <> "" or request("chk_cargo_filtro"&arr(i)&"_select") <> "" then
					db_string = db_string & " inner join informativo.informacao.tb_perfis as p "
					db_string = db_string & "	on p.cod_perfil=u.cod_perfil "

					db_total = db_total & " inner join informativo.informacao.tb_perfis as p "
					db_total = db_total & "	on p.cod_perfil=u.cod_perfil "
					
					if request("chk_area_filtro"&arr(i)&"_select") <> "" then
						db_string = db_string & " and p.cod_area in("&request("chk_area_filtro"&arr(i)&"_select")&") "
						db_total = db_total & " and p.cod_area in("&request("chk_area_filtro"&arr(i)&"_select")&") "
					end if
					if request("chk_cargo_filtro"&arr(i)&"_select") <> "" then
						db_string = db_string & " and p.cod_cargo in("&request("chk_cargo_filtro"&arr(i)&"_select")&") "
						db_total = db_total & " and p.cod_cargo in("&request("chk_cargo_filtro"&arr(i)&"_select")&") "
					end if
				end if

				db_total = db_total & " where u.cod_status_usuario=1 "

				db_string = db_string & " where u.cod_status_usuario=1 "
				db_string = db_string & ") as a "
				set rscount = getRs(db_string)
				if not rscount.eof then
					if i > 0 then
						retorno = retorno & ","
					end if
					retorno = retorno & "{"&replace(arr(i),",","")&" : '("&rscount("qtde")&" contato(s))'} "
				end if
				rscount.close

			else
				if i > 0 then
					retorno = retorno & ","
				end if
				retorno = retorno & "{"&replace(arr(i),",","")&" : '(0 contato)'} "
			end if
		next
		if retorno <> "" then
			retorno = retorno & ","
		end if
		if db_total <> "" then 
			db_total = "select count(a.cod_usuario) as qtde from (" & db_total & ") as a "
			set rscount = getRs(db_total)
			if not rscount.eof then
				retorno = retorno & "{qtde_total : '("&rscount("qtde")&" contato(s))'} "
			end if
			rscount.close
		else
			retorno = retorno & "{qtde_total : '(0 contato)'} "
		end if

	End if
	response.write "["&retorno&"]"

End Sub

sub getTemplates()
	dim db_string
	db_string = "select cod_layout_informativos,titulo,0 as selected from informativos.tb_layout_informativos where cod_status_layout=1 "
	retorno  = fn_combo(db_string,true,"")
	response.write retorno
end Sub

sub getLayout()
	dim db_string
	Dim rsLayout
	if request("cod_layout_informativos") <> "" then
		db_string = "select html from informativos.tb_layout_informativos where cod_layout_informativos="&request("cod_layout_informativos")
		set rsLayout = getRs(db_string)
		if not rsLayout.eof then
			response.write rsLayout("html")
		end if
		rsLayout.close
	else
		response.write ""
	end if
end Sub


Sub gravar()
	dim db_string
	Dim filtros
	Dim dt
	Dim data
	dt = split(request("data"),"/")
	data = dt(2)&"/"&dt(1)&"/"&dt(0)

	if request("cod_informativo") = "0" or request("cod_informativo") = "" then
		db_string = db_string & " set nocount on;"
		db_string = db_string & " declare @id bigint;"
		db_string = db_string & " insert into informativos.tb_informativos ("
		db_string = db_string & " cod_usuario_cadastro,	"
		db_string = db_string & " cod_usuario_alteracao, "
		db_string = db_string & " cod_status_informativo, "
		db_string = db_string & " dt_cadastro, "
		db_string = db_string & " dt_alteracao, "
		db_string = db_string & " titulo, "
		db_string = db_string & " corpo, "
		db_string = db_string & " dt_agendamento_envio, "
		db_string = db_string & " cod_assunto_informativo, "
		db_string = db_string & " fonte "
		db_string = db_string & " ) values ("
		db_string = db_string & vcod_usuario & ","
		db_string = db_string & vcod_usuario & ","
		db_string = db_string & request("cod_status_cadastro") & " , "
		db_string = db_string & " getdate(), "
		db_string = db_string & " getdate(), "
		db_string = db_string & " '"&request("titulo")&"', "
		db_string = db_string & " '"&replace(request("corpo"),vbcrlf,"")&"', "
		db_string = db_string & " '"&data&" "&request("hora")&":00', "
		db_string = db_string & " '"&request("cod_assunto_cadastro")&"', "
		db_string = db_string & " '"&request("fonte")&"' "
		db_string = db_string & " ); "
		db_string = db_string & " select @id=scope_identity(); "
		if request("filtros") <> "" then
			filtros = split(request("filtros"),",")
			for i=0 to ubound(filtros)
				if request("chk_reg_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativos.tb_informativos_regional ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_regional,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & " @id,"
					db_string = db_string & " cod_regional,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informacao.tb_regionais "
					db_string = db_string & " where cod_regional in("&request("chk_reg_filtro"&filtros(i)&"_select")&"));"
				end if

				if request("chk_uf_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativos.tb_informativos_uf ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_uf,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & " @id,"
					db_string = db_string & " cod_uf,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informacao.tb_ufs "
					db_string = db_string & " where cod_uf in("&request("chk_uf_filtro"&filtros(i)&"_select")&"));"
				end if

				if request("chk_ddd_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativos.tb_informativos_ddd ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_ddd,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & " @id,"
					db_string = db_string & " cod_ddd,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informacao.tb_ddds "
					db_string = db_string & " where cod_ddd in("&request("chk_ddd_filtro"&filtros(i)&"_select")&"));"
				end if

				if request("chk_area_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativos.tb_informativos_area ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_area,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & " @id,"
					db_string = db_string & " cod_area,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informacao.tb_areas "
					db_string = db_string & " where cod_area in("&request("chk_area_filtro"&filtros(i)&"_select")&"));"
				end if

				if request("chk_cargo_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativos.tb_informativos_cargo ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_cargo,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & " @id,"
					db_string = db_string & " cod_cargo,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informacao.tb_cargos "
					db_string = db_string & " where cod_cargo in("&request("chk_cargo_filtro"&filtros(i)&"_select")&"));"
				end if
			next
		end if
	else
		db_string = " update informativo.informativos.tb_informativos set "
		db_string = db_string & " cod_usuario_alteracao="&vcod_usuario&", "
		if request("cod_status_cadastro") <> ""  then
			db_string = db_string & " cod_status_informativo="&request("cod_status_cadastro")&", "
		end if
		db_string = db_string & " dt_alteracao=getdate(), "
		db_string = db_string & " titulo='"&request("titulo")&"', "
		db_string = db_string & " corpo='"&replace(request("corpo"),vbcrlf,"")&"', "
		db_string = db_string & " dt_agendamento_envio='"&data&" "&request("hora")&":00', "
		db_string = db_string & " cod_assunto_informativo="&request("cod_assunto_cadastro")&", "
		db_string = db_string & " fonte='"&request("fonte")&"' "
		db_string = db_string & " where cod_informativo="&request("cod_informativo")&";"
		db_string = db_string & " delete informativo.informativos.tb_informativos_regional where cod_informativo="&request("cod_informativo")&";"
		db_string = db_string & " delete informativo.informativos.tb_informativos_uf where cod_informativo="&request("cod_informativo")&";"
		db_string = db_string & " delete informativo.informativos.tb_informativos_ddd where cod_informativo="&request("cod_informativo")&";"
		db_string = db_string & " delete informativo.informativos.tb_informativos_area where cod_informativo="&request("cod_informativo")&";"
		db_string = db_string & " delete informativo.informativos.tb_informativos_cargo where cod_informativo="&request("cod_informativo")&";"
		if request("filtros") <> "" then
			filtros = split(request("filtros"),",")
			for i=0 to ubound(filtros)
				if request("chk_reg_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativo.informativos.tb_informativos_regional ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_regional,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & request("cod_informativo")&" ,"
					db_string = db_string & " cod_regional,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informativo.informacao.tb_regionais "
					db_string = db_string & " where cod_regional in("&request("chk_reg_filtro"&filtros(i)&"_select")&"));"
				end if

				if request("chk_uf_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativo.informativos.tb_informativos_uf ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_uf,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & request("cod_informativo")&","
					db_string = db_string & " cod_uf,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informativo.informacao.tb_ufs "
					db_string = db_string & " where cod_uf in("&request("chk_uf_filtro"&filtros(i)&"_select")&"));"
				end if

				if request("chk_ddd_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativo.informativos.tb_informativos_ddd ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_ddd,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & request("cod_informativo")&" ,"
					db_string = db_string & " cod_ddd,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informativo.informacao.tb_ddds "
					db_string = db_string & " where cod_ddd in("&request("chk_ddd_filtro"&filtros(i)&"_select")&"));"
				end if

				if request("chk_area_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativo.informativos.tb_informativos_area ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_area,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & request("cod_informativo")&" ,"
					db_string = db_string & " cod_area,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informativo.informacao.tb_areas "
					db_string = db_string & " where cod_area in("&request("chk_area_filtro"&filtros(i)&"_select")&"));"
				end if

				if request("chk_cargo_filtro"&filtros(i)&"_select") <> "" then
					db_string = db_string & " insert into informativo.informativos.tb_informativos_cargo ("
					db_string = db_string & " cod_informativo,"
					db_string = db_string & " cod_cargo,"
					db_string = db_string & " filtro "
					db_string = db_string & " ) ( "
					db_string = db_string & " select "
					db_string = db_string & request("cod_informativo")&","
					db_string = db_string & " cod_cargo,"
					db_string = db_string & filtros(i) & " "
					db_string = db_string & " from informativo.informacao.tb_cargos "
					db_string = db_string & " where cod_cargo in("&request("chk_cargo_filtro"&filtros(i)&"_select")&"));"
				end if
			next
		end if
	end if
	executeQuery(db_string)
End Sub

Sub getComunicado()
	Dim db_string
	Dim rsinf
	Dim rsfiltros
	Dim retorno
	Dim filtros 
	Dim i
	if request("cod_informativo") <> "" then
		db_string = "select	cod_informativo, "
		db_string = db_string & " cod_assunto_informativo, "
		db_string = db_string & " CONVERT(varchar(10),dt_agendamento_envio,103) as data, "
		db_string = db_string & " left(convert(varchar(25), dt_agendamento_envio, 108),5) as hora, "
		db_string = db_string & " cod_status_informativo, "
		db_string = db_string & " titulo,"
		db_string = db_string & " corpo,"
		db_string = db_string & " fonte"
		db_string = db_string & " from informativos.tb_informativos "
		db_string = db_string & " where cod_informativo="&request("cod_informativo")
		set rsinf = getRs(db_string)
		if not rsinf.eof then
			retorno = "{success : true, data: {"
			retorno = retorno & "'cod_informativo':'"&rsinf("cod_informativo")&"',"
			if rsinf("cod_status_informativo") = "1" or rsinf("cod_status_informativo") = "3" then
				retorno = retorno & "'editavel': true,"
			else
				retorno = retorno & "'editavel': false,"	
			end if
			retorno = retorno & "'dt':'"&rsinf("data")&"',"
			retorno = retorno & "'hora':'"&rsinf("hora")&"',"
			retorno = retorno & "'cod_status_informativo':'"&rsinf("cod_status_informativo")&"',"
			retorno = retorno & "'titulo':'"&rsinf("titulo")&"',"
			retorno = retorno & "'corpo':'"&rsinf("corpo")&"',"
			retorno = retorno & "'fonte':'"&rsinf("fonte")&"',"
		end if
		rsinf.close
		db_string = " select distinct filtro from informativos.tb_informativos_regional "
		db_string = db_string & "	where cod_informativo="&request("cod_informativo")
		db_string = db_string & "	union "
		db_string = db_string & "	select distinct filtro from informativos.tb_informativos_uf "
		db_string = db_string & "	where cod_informativo="&request("cod_informativo")
		db_string = db_string & "	union "
		db_string = db_string & "	select distinct filtro from informativos.tb_informativos_ddd "
		db_string = db_string & "	where cod_informativo="&request("cod_informativo")
		db_string = db_string & "	union "
		db_string = db_string & "	select distinct filtro from informativos.tb_informativos_area "
		db_string = db_string & "	where cod_informativo="&request("cod_informativo")
		db_string = db_string & "	union "
		db_string = db_string & "	select distinct filtro from informativos.tb_informativos_cargo "
		db_string = db_string & "	where cod_informativo="&request("cod_informativo")
		set rsfiltros = getRs(db_string)
		i = 0
		while not rsfiltros.eof
			if i > 0 then
				filtros = filtros & ","
			end if
			filtros = filtros & rsfiltros("filtro")
			i = i + 1
			rsfiltros.movenext
		wend
		retorno = retorno & " 'filtros' : '"&filtros&"' }}"
	End if
	response.write retorno
	response.end
End sub

Sub duplicar()
	Dim db_string
	if request("cod_informativo") <> "" and request("cod_usuario") <> "" then
		db_string = " exec informativos.sp_clona_informativo "&request("cod_informativo")&","&request("cod_usuario")
		executeQuery(db_string)
	end if
End Sub

Sub getCountFiltros()
	Dim db_string
	Dim rsfiltros
	Dim retorno
	db_string = "select (COUNT(a.filtro)*5) as qtde "
	db_string = db_string & " from "
	db_string = db_string & " ( "
	db_string = db_string & " select distinct filtro from informativo.informativos.tb_informativos_regional where cod_informativo="&request("cod_informativo")
	db_string = db_string & " union "
	db_string = db_string & " select distinct filtro from informativo.informativos.tb_informativos_uf where cod_informativo="&request("cod_informativo")
	db_string = db_string & " union "
	db_string = db_string & " select distinct filtro from informativo.informativos.tb_informativos_ddd where cod_informativo="&request("cod_informativo")
	db_string = db_string & " union "
	db_string = db_string & " select distinct filtro from informativo.informativos.tb_informativos_area where cod_informativo="&request("cod_informativo")
	db_string = db_string & " union "
	db_string = db_string & " select distinct filtro from informativo.informativos.tb_informativos_cargo where cod_informativo="&request("cod_informativo")
	db_string = db_string & " ) as a "
	set rsfiltros = getRs(db_string)
	if not rsfiltros.eof then
		if rsfiltros("qtde")&"" = "0" or rsfiltros("qtde")&"" = "" then
			retorno = "5"
		else
			retorno = rsfiltros("qtde")
		end if
	else
		retorno = "5"
	end if
	response.write retorno
	response.end
End Sub

%>